package com.lxf.education.service.impl;

import javax.annotation.Resource;
import javax.swing.*;

import com.lxf.education.dao.CourseMapper;
import com.lxf.education.dao.ResultMapper;
import com.lxf.education.dao.StudentListMapper;
import com.lxf.education.dao.Student_ResultMapper;
import com.lxf.education.pojo.CoursePojo;
import com.lxf.education.pojo.ReslutPojo;
import com.lxf.education.pojo.StudentPojo;
import com.lxf.education.pojo.TeacherPojo;
import com.lxf.education.service.ResultService;
import com.lxf.education.service.TeacherListService;
import com.lxf.education.utils.ResultVo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author:LuoXingFa;
* @version:Date:2022年4月27日上午10:58:24
*/
@Service
public class ResultServiceImpl implements ResultService {

	@Resource
	ResultMapper resultMapper;
	
	@Resource
	TeacherListService teacherListService;

	@Resource
    Student_ResultMapper student_resultMapper;

	@Override
	public ResultVo findAll() {
		List<ReslutPojo> reslutPojoList = resultMapper.findAll();

		return ResultVo.getSuccessVo("success",reslutPojoList);
	}

	@Override
	public ResultVo getResultByPage(Integer page, Integer limit) {
		// TODO Auto-generated method stub
		try {
			//计算出初始页
            Integer start = (page-1)*limit;
            //查询数据
            List<ReslutPojo> reslutPojos = resultMapper.getAllResult(start,limit);
            //根据id查询到课程
            for(ReslutPojo rPojo:reslutPojos) {
//				//查询学生数量
				List<ReslutPojo>  reslutPojoList= student_resultMapper.selectStudentByRId(rPojo.getRid());
            	int amount = reslutPojoList.size();
				rPojo.setRsamount(amount);
			}

            //查询总条数
            int count = resultMapper.finCount();
            ResultVo successVo = ResultVo.getSuccessVo("success",reslutPojos);
            //将总条数设置进去
            successVo.setCount(count);
            return successVo;

        }catch (Exception e){
            e.printStackTrace();
            return ResultVo.getFailVo("fails");
        }
	}
	
}
